using System.Windows.Forms;
using DrawTools.Editor;
using DrawTools.Editor.CanvasFigures;

namespace DrawTools.Tools
{
  /// <summary>
  ///   Base class for all tools which create new graphic object
  /// </summary>
  public abstract class ObjectTool : Tool
  {
    /// <summary>
    ///   Tool cursor.
    /// </summary>
    protected Cursor Cursor { get; set; }

    /// <summary>
    ///   Left mouse is released.
    ///   New object is created and resized.
    /// </summary>
    /// <param name="canvas"></param>
    /// <param name="e"></param>
    public override void OnMouseUp(IDrawingCanvas canvas, MouseEventArgs e)
    {
      if (canvas.GraphicsList.Count > 0)
        canvas.GraphicsList[0].Normalize();

      canvas.CaptureMouse = false;
      canvas.Refresh();
    }

    /// <summary>
    ///   Add new object to draw area.
    ///   Function is called when user left-clicks draw area,
    ///   and one of ToolObject-derived tools is active.
    /// </summary>
    /// <param name="canvas"></param>
    /// <param name="o"></param>
    protected void AddNewObject(IDrawingCanvas canvas, CanvasObject o)
    {
      canvas.GraphicsList.DeselectAll();

      o.IsSelected = true;
      canvas.GraphicsList.Add(o);

      canvas.CaptureMouse = true;
      canvas.Refresh();
    }
  }
}